<template>
  <div>
    <div class="toolbar">
      <el-button type="primary" v-if="hasRight('create')" @click="showDetail('create')">新增</el-button>
    </div>
    <el-table :data="engineers" v-loading="loading">
      <el-table-column prop="mobilePhone" label="手机号码" width="180"></el-table-column>
      <el-table-column prop="realName" label="姓名"></el-table-column>
      <el-table-column prop="idCard" label="证件号"></el-table-column>
      <el-table-column prop="status" label="状态">
        <template scope="scope">
          <el-tag
            :type="scope.row.status === '1' ? 'success' : 'gray'"
            close-transition>{{scope.row.status === '1' ? '在用' : '停用'}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="120" inline-template align="center">
        <el-button @click="showDetail(row.pkid)" type="text" size="small">查看详情</el-button>
      </el-table-column>
    </el-table>
    <el-pagination class="page"
                   @current-change="handleCurrentChange"
                   :current-page="1"
                   :page-size="10"
                   layout="total, prev, pager, next, jumper"
                   :total="page.totalRecord">
    </el-pagination>
  </div>
</template>
<style scoped>
  .toolbar{
    padding: 10px;
  }
  .page{
    text-align: right;
    margin: 10px 0px;
  }
</style>
<script>
  import mixin from '../../../mixin/rights'
  import api from '../../../api/engineer'

  export default {
    data () {
      return {
        engineers: [],
        page: {},
        loading: false
      }
    },
    mixins: [mixin],
    created () {
      this.loading = true
      api.getByPage(1, 10).then((resp) => {
        this.engineers = resp.body.data
        this.page = resp.body.page
        this.loading = false
      })
    },
    methods: {
      handleCurrentChange: function (pageNo) {
        this.loading = true
        api.getByPage(pageNo, 10).then((resp) => {
          this.engineers = resp.data
          this.loading = false
        })
      },
      showDetail: function (id) {
        this.$router.push({path: 'engineer/' + id})
      }
    }
  }
</script>
